axios.interceptors.response.use(
    function(response){
        console.log(response)
        let {status,message}=response.data;
        if(status===1){
            layer.msg(message)
        }
        return response;
    },function(error){
        console.log(error.response );
        let{message}=error.response.data;
       layer.msg(message);
        return Promise.rejiect(error);
    })

$('.login a').on('click',function(){
    $('.register').show();
});
$('.register a').on('click',function(){
    $('.register').hide();
});
$('.login form').on('submit',function(e){
    e.preventDefault();
    let data = $(this).serialize();
    console.log(data);
    axios.post('http://www.itcbc.com:8080/api/login',data).then(res=>{
        let{status,message,token}=res.data;
        if(status===0){
            localStorage.setItem('token',token);
            layer.msg(message ,{time :3000},()=>{
                location.href ='./index.html'
            }) 
        }
    })
});
$('.register form').on('click',function(e){
    e.preventDefault();
    let data = $(this).serialize();
    axios.post('http://www.itcbc.com:8080/api/reguser',data).then(res =>{
        let{status,message, token}= res.data;
        if(status===0){
            layer.msg(message);
            $('.register').hide();
            $(this)[0].reset();
        }
    })
})
let form = layui.form;
console.log(form)
 form.verify({
     len: [/^\S{6,12}$/,'输入6~12位数字'],
     same:function(val){
         let pwd = $('.pwd').val();
        if(pwd !==val)
        return '密码不相同'
     }
    })